package controller

import (
	"encoding/json"
	"github.com/astaxie/beego"
)

type UserController struct {
	beego.Controller
}

type LIKE struct {
	Food   string
	Watch  string
	Listen string
}

type JSONS struct {
	//必须的大写开头
	Code string
	Msg  string
	User []string `json:"user_info"` //key重命名,最外面是反引号
	Like LIKE
}

func (c *UserController) Get() {
	data := &JSONS{"100", "获取成功",
		[]string{"maple", "18"}, LIKE{"蛋糕", "电影", "音乐"}}
	c.Data["json"] = data
	c.ServeJSON()
}

func (c *UserController) Post() {
	data := &JSONS{"100", "post success",
		[]string{"maple", "18"}, LIKE{"蛋糕", "电影", "音乐"}}
	c.Data["json"] = data
	c.ServeJSON()
}

type Result struct {
	Code int
	Msg  string
	Data string
}

func (c *UserController) Test() {
	result := Result{1, "this no error", "data"}
	jsonData, _ := json.Marshal(result)
	c.Ctx.WriteString(string(jsonData))
}
